using System.Collections.Generic;
using UnityEngine;
using QFramework;

namespace ProjectSurvival
{
    public partial class SimpleBasketBall : ViewController
    {
        private List<BasketBall> _basketBalls = new List<BasketBall>();

        void CreatBoll()
        {
            _basketBalls.Add(Ball.InstantiateWithParent(this)
                .SyncPosition2DFrom(this)
                .Show()
            );
        }

        void CreatBolls(int count)
        {
            for (int i = 0; i < count; i++)
            {
                CreatBoll();
            }
        }
        void Start()
        {
            Global.SimpleBasketBallCount.Or(Global.AdditionalFlyThingCount).Register(() =>
            {
                int CreatCount = Global.SimpleBasketBallCount.Value + Global.AdditionalFlyThingCount.Value -
                                 _basketBalls.Count;
                if (CreatCount>0)
                {
                    CreatBolls(CreatCount);
                }
            }).UnRegisterWhenGameObjectDestroyed(gameObject);
            CreatBoll();
        }
    }
}